package com.eedi.framework.event.convert;

import com.eedi.framework.common.event.annotations.event.EediEventPoint;
import com.eedi.framework.event.controller.vo.SysEventConsumerCreateReq;
import com.eedi.framework.event.controller.vo.SysEventConsumerResp;
import com.eedi.framework.event.controller.vo.SysEventObsOrgResp;
import com.eedi.framework.event.core.api.EediConsumerCreateReq;
import com.eedi.framework.event.core.api.EediConsumerResp;
import com.eedi.framework.event.dal.dataobject.SysEventConsumerDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface SysEventConsumerConvert {
    SysEventConsumerConvert INSTANCE = Mappers.getMapper(SysEventConsumerConvert.class);

    SysEventConsumerCreateReq convert(SysEventObsOrgResp resp);

    @Mapping(source = "sysEventPoint", target = "sysEventPointCode", qualifiedByName = "pointToCode")
    @Mapping(source = "sysEventPoint", target = "sysEventPointDesc", qualifiedByName = "pointToDesc")
    SysEventConsumerDO convert(SysEventConsumerCreateReq req);

    SysEventConsumerResp convert(SysEventConsumerDO consumerDO);

    SysEventConsumerCreateReq convert(EediConsumerCreateReq req);

    @Named("pointToCode")
    default String pointToCode(EediEventPoint point) {
        return point.getCode();
    }

    @Named("pointToDesc")
    default String pointToDesc(EediEventPoint point) {
        return point.getDesc();
    }

    EediConsumerResp convertEediConsumerResp(SysEventConsumerResp resp);

    List<EediConsumerResp> convertEediConsumerResp(List<SysEventConsumerResp> resp);
}
